package com.atguigu.day17_1.test01;

import java.util.*;

/**
 * @author fenge
 */
public class Test01 {
    public static void main(String[] args) {
        HashMap<Character,Integer> map = new HashMap<>();
        String str = "Your future depends on your dreams, so go to sleep.";
        str = str.replaceAll("[^a-zA-Z]","");
//        System.out.println(str);
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (!map.containsKey(chars[i])){
                map.put(chars[i],1);
            }
            else {
                int count = map.get(chars[i]);
                map.put(chars[i],++count);
            }
        }
        System.out.println(map);
//        Integer[] nums =(Integer[]) map.values().toArray();
        Set<Map.Entry<Character,Integer>> entries = map.entrySet();
        int max = 0;
        for (Map.Entry<Character, Integer> entry : entries) {
            if (entry.getValue()>max)
                max = entry.getValue();
        }
        for (Map.Entry<Character, Integer> entry : entries) {
            if (entry.getValue()==max)
                System.out.println("出现次数最多的字母是:"+entry.getKey()+",出现了"+entry.getValue()+"次");
        }
    }
}
